package mx.com.fractal.ristorante.service.impl;

import javax.ejb.Singleton;
import javax.interceptor.Interceptors;

import mx.com.fractal.ristorante.dao.MesaDAO;
import mx.com.fractal.ristorante.dto.MesaDTO;
import mx.com.fractal.ristorante.exception.ObjectAlreadyExistException;
import mx.com.fractal.ristorante.service.MesaService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

@Singleton
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class MesaServiceImpl implements MesaService{
	
	@Autowired
	private MesaDAO mesaDAO;
	
	public void save(MesaDTO mesa) throws Exception {
		try{
			Integer id = mesaDAO.save(mesa);
			mesa.setIdMesa(id);
		}catch(DuplicateKeyException e){
			throw new ObjectAlreadyExistException("Ya existe el objeto --> "+mesa,e);
		}
	}

}
